'''A listener that uses API version 3'''

import os.path

class ListenAPI3(object):

    ROBOT_LISTENER_API_VERSION = '3'

    def __init__(self):
        outpath = os.path.join(os.getenv('TEMPDIR'), 'listen_api3.txt')
        self.outfile = open(outpath, 'w')

    def start_suite(self, testrun):
        self.outfile.write('SUITE START: ' + testrun.suite.name + "\n")

    def end_suite(self, testrun):
        self.outfile.write('SUITE END: ' + testrun.suite.name + "\n")

    def start_test(self, testrun):
        self.outfile.write('TEST START: ' + testrun.testcase.name + "\n")
    
    def end_test(self, testrun):
        self.outfile.write('TEST END: ' + testrun.testcase.name + "\n")

    def start_keyword(self, testrun):
        self.outfile.write('KW START: ' + testrun.keyword.name + "\n")
    
    def end_keyword(self, testrun):
        self.outfile.write('KW END: ' + testrun.keyword.name + "\n")

    def close(self):
        self.outfile.close()
